package edu.mju.B9_3.entity;

import edu.mju.B9_2.entity.Source;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;


/**
 * @Author: wyp
 * @Date: 2020/10/12 21:39
 */
public class JuiceMaker3 implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String beverageShop = null;
    private Source source = null;

    public String getBeverageShop() {
        return beverageShop;
    }

    public void setBeverageShop(String beverageShop) {
        this.beverageShop = beverageShop;
    }

    public Source getSource() {
        return source;
    }

    public void setSource(Source source) {
        this.source = source;
    }

    public String makeJuice(){
        String juice = "由"+beverageShop+"饮品店，提供的"+source.getSize()+source.getSugar()+source.getFruit();
        return juice;
    }

    //自定义初始化方法
    @PostConstruct
    public void init(){
        System.out.println("["+this.getClass().getSimpleName()+"]对象自定义初始化方法");
    }

    //自定义销毁方法
    public void myDestory(){
        System.out.println("["+this.getClass().getSimpleName()+"]对象自定义销毁方法myDestory方法");
    }


    //执行顺序1
    public void setBeanName(String name) {
        System.out.println("["+this.getClass().getSimpleName()+"]对象：调用BeanNameAware接口的setBeanName方法，name:"+name);
    }

    //执行顺序2
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("["+this.getClass().getSimpleName()+"]对象：调用BeanFactoryAware接口的setBeanFactory方法");
    }

    //执行顺序3
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("["+this.getClass().getSimpleName()+"]对象：调用ApplicationContextAware接口的setApplicationContext方法");
    }

    //中间调用BeanPostProcessorImpl.java的postProcessBeforeInitialization()方法

    //执行顺序4
    public void afterPropertiesSet() throws Exception {
        System.out.println("["+this.getClass().getSimpleName()+"]对象：调用InitializingBean接口的afterPropertiesSet方法");
    }

    //中间调用BeanPostProcessorImpl.java的postProcessAfterInitialization()方法

    //执行顺序5
    public void destroy() throws Exception {
        System.out.println("["+this.getClass().getSimpleName()+"]对象：调用DisposableBean接口的destory方法");
    }




}
